﻿@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.Abp.Identity.Localization
@using Volo.Abp.Identity.Web.Pages.Identity.Users
@using Volo.Abp.Localization
@using Volo.Abp.ObjectExtending
@using Volo.Abp.Data
@model EditModalModel
@inject IHtmlLocalizer<IdentityResource> L
@inject IStringLocalizerFactory StringLocalizerFactory
@{
    Layout = null;
}
<form method="post" asp-page="/Identity/Users/EditModal">
    <abp-modal>
        <abp-modal-header title="@L["Edit"].Value"></abp-modal-header>
        <abp-modal-body>
            <abp-tabs name="create-user-modal-tabs">
                <abp-tab title="@L["UserInformations"].Value">
                    <input asp-for="UserInfo.Id" />
                    <input asp-for="UserInfo.ConcurrencyStamp" />
                    <abp-input asp-for="UserInfo.UserName" />
                    <abp-input asp-for="UserInfo.Name" />
                    <abp-input asp-for="UserInfo.Surname" />
                    <abp-input asp-for="UserInfo.Password" />
                    <abp-input asp-for="UserInfo.Email" />
                    <abp-input asp-for="UserInfo.PhoneNumber" />
                    <abp-input asp-for="UserInfo.LockoutEnabled" />

                    @foreach (var propertyInfo in ObjectExtensionManager.Instance.GetProperties<EditModalModel.UserInfoViewModel>())
                    {
                        if (!propertyInfo.Name.EndsWith("_Text"))
                        {
                            if (propertyInfo.Type.IsEnum || !propertyInfo.Lookup.Url.IsNullOrEmpty())
                            {
                                <abp-select asp-for="UserInfo.ExtraProperties[propertyInfo.Name]"
                                            label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)"
                                            autocomplete-api-url="@propertyInfo.Lookup.Url"
                                            autocomplete-selected-item-name="@Model.UserInfo.GetProperty(propertyInfo.Name+"_Text")"
                                            autocomplete-selected-item-value="@Model.UserInfo.GetProperty(propertyInfo.Name)"
                                            autocomplete-filter-param-name="@propertyInfo.Lookup.FilterParamName"
                                            autocomplete-items-property-name="@propertyInfo.Lookup.ResultListPropertyName"
                                            autocomplete-display-property-name="@propertyInfo.Lookup.DisplayPropertyName"
                                            autocomplete-value-property-name="@propertyInfo.Lookup.ValuePropertyName"></abp-select>
                            }
                            else
                            {
                                <abp-input type="@propertyInfo.GetInputType()"
                                           asp-for="UserInfo.ExtraProperties[propertyInfo.Name]"
                                           label="@propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory)"
                                           asp-format="@propertyInfo.GetInputFormatOrNull()"
                                           value="@propertyInfo.GetInputValueOrNull(Model.UserInfo.GetProperty(propertyInfo.Name))" />
                            }
                        }
                    }

                </abp-tab>
                <abp-tab title="@L["Roles"].Value">
                    @for (var i = 0; i < Model.Roles.Length; i++)
                    {
                        var role = Model.Roles[i];
                        <abp-input abp-id-name="@Model.Roles[i].IsAssigned" asp-for="@role.IsAssigned" label="@role.Name" />
                        <input abp-id-name="@Model.Roles[i].Name" asp-for="@role.Name" />
                    }
                </abp-tab>
            </abp-tabs>
        </abp-modal-body>
        <abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
    </abp-modal>
</form>
